package com.ntv.presentation.spring.web.news;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.ntv.common.NewsCategory;
import com.ntv.domain.INews;
import com.ntv.service.news.INewsAppService;

@Controller
@RequestMapping("/news_type_home.html")
public class NewsCategoryHomeController {
	private static final Logger logger = Logger
			.getLogger(NewsCategoryHomeController.class);
	@Autowired
	private INewsAppService newsAppService;

	public void setNewsAppService(INewsAppService newsAppService) {
		this.newsAppService = newsAppService;
	}

	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView setupForm(@RequestParam("id")
	int id, ModelMap model) throws Exception {
		List<INews> newsList = newsAppService.getNewsListByTypeId(new Long(id));
		Map model1 = new HashMap();
		model1.put("news", newsList);
		model1.put("selectedNewsCagetory", NewsCategory.getNewsCategory(
				new Long(id)).getLabel());
		ModelAndView mav = new ModelAndView("home.type.news", model1);
		return mav;
	}

	/*
	 * public ModelAndView handleRequestInternal(HttpServletRequest request,
	 * HttpServletResponse response) throws Exception {
	 * 
	 * String id = (String)request.getParameter("id");
	 * 
	 * List<INews> newsList = newsAppService.getNewsListByTypeId(new Long(id));
	 * Map model = new HashMap(); model.put("news", newsList);
	 * model.put("selectedNewsCagetory", NewsCategory.getNewsCategory(new
	 * Long(id)).getLabel()); ModelAndView mav = new
	 * ModelAndView("home.type.news", model); return mav; }
	 */

}
